package org.poseidon.report.controller;

import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.poseidon.common.annotation.Log;
import org.poseidon.common.core.controller.BaseController;
import org.poseidon.common.core.domain.CommonResult;
import org.poseidon.common.core.page.TableDataInfo;
import org.poseidon.common.enums.BusinessType;
import org.poseidon.common.utils.poi.ExcelUtil;
import org.poseidon.report.converter.ProductConverter;
import org.poseidon.report.domain.BuProduct;
import org.poseidon.report.domain.vo.ProductVO;
import org.poseidon.report.input.BuProductInput;
import org.poseidon.report.service.IBuProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 业务域Controller
 * 
 * @author gfc
 * @date 2022-02-22
 */
@Api(tags = "业务域")
@RestController
@RequestMapping("/report/product")
public class BuProductController extends BaseController
{
    @Autowired
    private IBuProductService buProductService;

    /**
     * 查询业务域列表
     */
    @PreAuthorize("@ss.hasPermi('system:product:list')")
    @PostMapping("/list")
    @ApiOperation(value = "查询业务域列表")
    public TableDataInfo list(@RequestBody BuProductInput input)
    {
        BuProduct buProduct   = ProductConverter.convertToDomain(input);
        PageHelper.startPage(input.getPageNum(),input.getPageSize());
        List<BuProduct> list = buProductService.selectBuProductList(buProduct);
        return getDataTable(list);
    }
    @ApiOperation(value = "添加项目时-获取业务域列表下拉框")
    @GetMapping("/list")
    public TableDataInfo list(){
        List<ProductVO> list = buProductService.selectAll();
        return getDataTable(list);
    }

    /**
     * 导出业务域列表
     */
    @ApiOperation(value ="导出业务域列表 暂时不做")
    @PreAuthorize("@ss.hasPermi('system:product:export')")
    @Log(title = "业务域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuProduct buProduct)
    {
        List<BuProduct> list = buProductService.selectBuProductList(buProduct);
        ExcelUtil<BuProduct> util = new ExcelUtil<BuProduct>(BuProduct.class);
        util.exportExcel(response, list, "业务域数据");
    }

    /**
     * 获取业务域详细信息
     */
    @ApiOperation(value ="获取业务域详细信息")
    @PreAuthorize("@ss.hasPermi('system:product:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return CommonResult.success(buProductService.selectBuProductById(id));
    }

    /**
     * 新增业务域
     */
    @ApiOperation(value ="新增业务域")
    @PreAuthorize("@ss.hasPermi('system:product:add')")
    @Log(title = "业务域", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody BuProduct buProduct)
    {
        return toAjax(buProductService.insertBuProduct(buProduct));
    }

    /**
     * 修改业务域
     */
    @ApiOperation(value ="修改业务域")
    @PreAuthorize("@ss.hasPermi('system:product:edit')")
    @Log(title = "业务域", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody BuProduct buProduct)
    {
        return toAjax(buProductService.updateBuProduct(buProduct));
    }

    /**
     * 删除业务域
     */
    @PreAuthorize("@ss.hasPermi('system:product:remove')")
    @Log(title = "业务域", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove")
    @ApiOperation(value = "删除业务域 单选和多选")
    public CommonResult remove(@RequestBody List<Long> ids)
    {
        return toAjax(buProductService.deleteBuProductByIds(ids));
    }
}
